package com.shiku.imserver.repository;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.shiku.imserver.common.AbstractService;
import org.bson.Document;
import org.bson.types.ObjectId;

public abstract class BaseRepository extends AbstractService {
    protected static final int DB_REMAINDER = 10000;
    protected static final int MIN_USERID = 100000;

    /* access modifiers changed from: protected */
    public MongoCollection<Document> getCollection(MongoDatabase database, long userId) {
        return database.getCollection(getCollectionName(database.getName(), userId));
    }

    /* access modifiers changed from: protected */
    public String getCollectionName(String dbName, long userId) {
        long remainder = 0;
        if (userId > 100000) {
            remainder = userId / 10000;
        }
        return remainder + "";
    }
    public String getCollectionName(ObjectId id) {
        if (null == id) {
            throw new RuntimeException("ObjectId  is  null !");
        } else {
            int remainder = 0;
            int counter = id.getCounter();
            remainder = counter / 10000;
            return String.valueOf(remainder);
        }
    }

}
